/*
 * @descripttion: 封装常用方式
 * @author: cp
 * @Date: 2021-04-25 11:26:54
 */



/**
 * @descripttion 验证数组是否为空
 * @param arr 数组
 * @returns true / false
 */
export function isArrayEmpty(arr: String) {
	if(arr && arr instanceof Array && arr.length>0){
		return false;
	}else{
		return true;
	}
}

/**
 * @descripttion 验证手机号是否合格
 * @param phoneStr 手机号
 * @returns true / false
 */
export function isPhone(phoneStr: string){
	let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
	if (!myreg.test(phoneStr)) {
		return false;
	} else {
		return true;
	}
}


/**
 * @descripttion 验证身份证是否合格
 * @param idCardStr 身份证号码
 * @returns true / false
 */
export function isIdCard(idCardStr: string) {
	let idcardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/
	if (idcardReg.test(idCardStr)) {
		return true
	} else {
		return false
	}
}

/**
 * @descripttion 验证车牌号是否合格
 * @param vehicleNumber 车牌号
 * @returns true / false
 */
export function isVehicleNumber(vehicleNumber:string) {
	let xreg=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([DF][A-HJ-NP-Z0-9][0-9]{4}$))/;
	let creg=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
	if(vehicleNumber.length == 7){
		return creg.test(vehicleNumber);
	} else if(vehicleNumber.length == 8){
		return xreg.test(vehicleNumber);
	} else{
		return false;
	}
}


/**
 * 
 * @param IDCard 身份证
 * @returns 年龄，出生年月，性别
 */
export function tools_calcIdentiyInfo(IDCard: any) {
	// 获取性别
	let sex = parseInt(IDCard.substr(16, 1)) % 2 == 1 ? '男' : '女';
	let brith = IDCard.substring(6, 10) + "-" + IDCard.substring(10, 12) + "-" + IDCard.substring(12, 14);
	//获取出生年月日
	//IDCard.substring(6,10) + "-" + IDCard.substring(10,12) + "-" + IDCard.substring(12,14);
	let yearBirth = IDCard.substring(6, 10);
	let monthBirth = IDCard.substring(10, 12);
	let dayBirth = IDCard.substring(12, 14);
	//获取当前年月日并计算年龄
	let myDate = new Date();
	let monthNow:number = myDate.getMonth() + 1;
	let dayNow:number = myDate.getDay();
	let age = myDate.getFullYear() - yearBirth;
	if (monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)) {
		age--;
	}
	let obj = {
		sex,
		birth: brith,
		age
	}
	return obj;
}

/**
 * 获取当前时间
 * @param blo true / false
 * @returns 当前时间 / 当前日期
 */
export function timeFormate (blo: boolean) {
	let year = new Date().getFullYear()
	let Seconds = new Date().getSeconds()
	let month = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1
	let date = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
	let hh = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours()
	let mm = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
	//定义参数
	if (blo) return year + '-' + month + '-' + date;
	return year + '-' + month
}